#include <vector>
#include <algorithm>
#include <stdlib.h>

using namespace std;

class Solution {
public:
    int threeSumClosest(vector<int> &num, int target) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        sort(num.begin(),num.end());
		int min = 1000000;
		int cur = num.size() - 1;
		int rus;
		for(int i = 0; i < num.size(); ++i) {
			int cur = num.size() - 1;
			for(int j = i + 1; j < num.size(); ++j) {
				int gap = abs(num[i] + num[j] + num[cur] - target);
				for(int k = cur; k > j; --k) {
					int tmp = abs(num[i] + num[j] + num[k] - target);
					if(tmp > gap)
						break;
					if(tmp < min) {
						rus = num[i] + num[j] + num[k];
						min = tmp;
					}
					gap = tmp;
				}
			}
		}
		return rus;
    }
};

int main(int argc, char *argv[])
{
	printf("Hello, world\n");
	
	return 0;
}